<template>
	<div :class="['app-editor-container', 'app-switch', `app-switch-${name}`]">
		<a-switch
			:checked="curValue"
			:size="size"
			:disabled="disabled || readOnly"
			@change="onChange"
		/>
	</div>
</template>

<script setup lang="ts">
import { IEvent } from '@/core';
import { computed, Ref } from 'vue';
import { switchProps } from './switch';
interface EditorEmit {
	(name: 'component-action', value: IEvent<string>): void;
}
const props = defineProps(switchProps);
const emit = defineEmits<EditorEmit>();
const curValue: Ref<boolean> = computed(() => {
	if (!props.value) {
		return false;
	} else {
		return true;
	}
});
const onChange = (value: any) => {
	emit('component-action', {
		name: `${props.name}`,
		action: 'valueChange',
		data: value ? 1 : 0,
	});
};
</script>
